package com.llyb.tingshu.user.strategy.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.llyb.tingshu.model.user.UserPaidAlbum;
import com.llyb.tingshu.user.mapper.UserPaidAlbumMapper;
import com.llyb.tingshu.user.strategy.ItemTypeStrategy;
import com.llyb.tingshu.vo.user.UserPaidRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("1001")
public class AlbumStrategy implements ItemTypeStrategy {

    @Autowired
    private UserPaidAlbumMapper userPaidAlbumMapper;


    /**
     * 保存付费记录
     *
     * @param userPaidRecordVo
     */
    @Override
    public void savePaidRecord(UserPaidRecordVo userPaidRecordVo) {
        // 防止添加重复数据
        if (userPaidAlbumMapper.selectCount(new LambdaQueryWrapper<UserPaidAlbum>()
                .eq(UserPaidAlbum::getUserId, userPaidRecordVo.getUserId())
                .eq(UserPaidAlbum::getAlbumId, userPaidRecordVo.getItemIdList().get(0)))>0){
            return;
        }
        // 专辑
        UserPaidAlbum userPaidAlbum = new UserPaidAlbum();
        userPaidAlbum.setUserId(userPaidRecordVo.getUserId());
        userPaidAlbum.setAlbumId(userPaidRecordVo.getItemIdList().get(0));
        userPaidAlbum.setOrderNo(userPaidRecordVo.getOrderNo());
        userPaidAlbumMapper.insert(userPaidAlbum);
    }
}
